Repository navigation
Conversation
Out-of-vocabulary freeze types are injected through model_copy, which skips validation the same way the upstream response path does, instead of widening the field to a plain string.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-26 14:03:52.266339810 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-26 14:03:41.254266297 +0000
@@ -5067,8 +5067,6 @@
--> tests/unit_tests/services/retention/workflow_run/test_restore_archived_workflow_run.py:760:16
ERROR `in` is not supported between `Literal['not found']` and `None` [not-iterable]
--> tests/unit_tests/services/retention/workflow_run/test_restore_archived_workflow_run.py:894:16
-ERROR Argument `str` is not assignable to parameter `freeze_type` with type `Literal['', 'email_domain_suspended', 'freeze']` in function `services.billing_client.saas.CheckAccountInFreezeReply.model_construct` [bad-argument-type]
- --> tests/unit_tests/services/test_billing_service.py:373:87
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `ConversationStatus | SQLCoreOperations[ConversationStatus]` in function `models.model.Conversation.__init__` [bad-argument-type]
--> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:117:16
ERROR Object of class `object` has no attribute `id` [missing-attribute]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46407 +/- ##
==========================================
- Coverage 90.53% 90.52% -0.01%
==========================================
Files 6608 6608
Lines 410585 410691 +106
Branches 82396 82394 -2
==========================================
+ Hits 371706 371781 +75
- Misses 32489 32512 +23
- Partials 6390 6398 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… tests `CheckAccountInFreezeReply.freeze_type` was generated as a closed `Literal`, but the value comes from a proto enum, so a dify-saas deployment older or newer than the committed snapshot can send a member the spec never listed. The only consumer, `BillingService.get_email_freeze_type`, already treats such a value as valid (`case _`), so the literal only moved the failure from that fallback into pydantic validation and made it log to Sentry on every reply from an older server. The generated model now declares `str`, and the test builds a real `CheckAccountInFreezeReply` through validation instead of `model_construct` plus `model_copy`. Since `saas.py` is a generated artefact guarded by `--check`, the change lands in `generate_billing_client.py` as an explicit allowlist of open enum fields, with a check that fails generation if an entry stops naming an enum field or disappears from the snapshot. Verified: `generate_billing_client.py --check` exits 0, the strict pyrefly run stays at the 29 missing-import baseline with no new warnings, `test_billing_service.py` passes 30 tests, and ruff is clean.
|
Fixed at the origin as suggested — and since
Verified: |
The allowlist only earns its place if a stale entry is caught, so the new tests pin both directions: an entry that stops naming an enum field and an entry that no longer appears in the snapshot each fail generation. The rendering tests also fix the contract that an open enum field becomes `str` while nullability and presence rules still apply, which is what lets the billing client accept a value the committed spec never listed.
… helper `BillingService.get_model_provider_payment_link` was decorated with `warnings.deprecated`, so both its one product caller and its unit test had to carry a `# pyrefly: ignore [deprecated]` comment. The endpoint it serves is already marked deprecated in the console OpenAPI surface, and a route that still exists cannot be "migrated away from" by a warning. Remove the decorator and its now unused `warnings.deprecated` import, and record the status in the helper's docstring instead. Both ignores go away with the diagnostic.
There was a problem hiding this comment.
3 inline suggestions at 13c3a9611c, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
| class CheckAccountInFreezeReply(BillingModel): | ||
| data: bool | ||
| freeze_type: Literal["", "freeze", "email_domain_suspended"] = Field(alias="freezeType") | ||
| freeze_type: str = Field(alias="freezeType") |
There was a problem hiding this comment.
why this changed from literal?
There was a problem hiding this comment.
freezeType is an open proto enum, not a closed one. A dify-saas deployment older or newer than this committed spec snapshot can return a value the spec never listed. With Literal[...], pydantic would reject that reply with a ValidationError even though the consumer can still read and act on it — turning a harmless new enum value into a spurious error in Sentry.
The consumer of CheckAccountInFreezeReply.freeze_type already matches with a case _ fallback, so widening to str loses no safety. The change is made in the generator (api/dev/generate_billing_client.py), not by hand-editing the generated saas.py (api/AGENTS.md forbids editing generated files): a minimal OPEN_ENUM_FIELDS allowlist keyed by (schema, wire name) renders just this one field as str. The allowlist comment says to keep it minimal and to drop the entry once the upstream spec removes the enum.
Every other enum field stays Literal — only fields whose consumer already handles unknown values are widened.
Resolve the project-excludes conflict by three-way comparison: keep entries each side still excludes, drop entries upstream graduated, append entries upstream newly excluded. Result 140 entries.
# Conflicts: # api/tests/unit_tests/pyrefly.toml
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at be40ea9da3, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 1 review thread is still unresolved.
dify-codereview
Part of the pyrefly strict-mode migration: this file leaves
project-excludes.api/tests/unit_tests/pyrefly.tomlnow carries real annotations, and the remaining diagnostics it exposed were fixed rather than suppressed. Nopyrefly: ignore/type: ignore/cast/typing.Anywas added.Verification:
pyrefly checkontests/unit_tests/pyrefly.tomlreports 29 errors (all pre-existingmissing-importfor optional packages) and 0 warnings with 0 diagnostics left in the target file;pytestpasses match the pre-change baseline;ruff checkandruff format --checkpass.